package com.example.yogurtsystem.controller;

import com.example.yogurtsystem.dto.ResultDTO;
import com.example.yogurtsystem.entity.Drinks;
import com.example.yogurtsystem.service.DrinksService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author ZXB
 * @version 1.0.0
 * @ClassName DrinksController
 * @Description TODO
 * @Date 2021/8/14 15:53
 */
@RestController
@RequestMapping("/drinks/")
@CrossOrigin
@Api("饮品表控制器")
public class DrinksController {

    @Autowired
    private DrinksService drinksService;

    @PostMapping("insertDrinks")
    @ApiOperation("新增饮品")
    public ResultDTO insertDrinks(@RequestBody  Drinks drinks){
        drinksService.insertDrinks(drinks);
        return ResultDTO.requestSuccess("新增饮品成功");
    }

    @PostMapping("updateDrinks")
    @ApiOperation("更新饮品")
    public ResultDTO updateDrinks(@RequestBody Drinks drinks){
        drinksService.updateDrinks(drinks);
        return ResultDTO.requestSuccess("更新饮品成功");
    }

    @PostMapping("deleteDrinks")
    @ApiOperation("删除饮品")
    public ResultDTO deleteDrinks(@RequestParam("id") String id){
        drinksService.deleteDrinks(id);
        return ResultDTO.requestSuccess("删除饮品成功");
    }

    @GetMapping("selectDrinksByLimit")
    @ApiOperation("查询饮品")
    public ResultDTO selectDrinksByLimit(int pageNum, int pageSize, String name) {
        return drinksService.selectDrinksByLimit(pageNum, pageSize, name);
    }

    @GetMapping("/getDrinkList")
    public ResultDTO<?> getDrinkList(){
        return ResultDTO.requestSuccess(drinksService.getDrinkList());
    }

}
